// TextToSpeechManager.cpp
#include "TextToSpeechManager.h"

TextToSpeechManager::TextToSpeechManager(QObject *parent) : QObject(parent) {
    // 创建文字转语音对象
    m_tts = new QTextToSpeech(this);

    // 尝试设置中文语音
    QVector<QLocale> locales = m_tts->availableLocales();
    for (const QLocale &locale : locales) {
        if (locale.language() == QLocale::Chinese) {
            m_tts->setLocale(locale);
            break;
        }
    }

    // 连接状态变化信号
    connect(m_tts, &QTextToSpeech::stateChanged, this, &TextToSpeechManager::stateChanged);
}

TextToSpeechManager::~TextToSpeechManager() {
    // QTextToSpeech 会自动清理
}

void TextToSpeechManager::speak(const QString &text) {
    m_tts->say(text);
}

void TextToSpeechManager::stop() {
    m_tts->stop();
}

void TextToSpeechManager::pause() {
    m_tts->pause();
}

void TextToSpeechManager::resume() {
    m_tts->resume();
}

void TextToSpeechManager::setRate(double rate) {
    m_tts->setRate(rate);
}

void TextToSpeechManager::setPitch(double pitch) {
    m_tts->setPitch(pitch);
}

void TextToSpeechManager::setVolume(double volume) {
    m_tts->setVolume(volume);
}

void TextToSpeechManager::setVoice(const QVoice &voice) {
    m_tts->setVoice(voice);
}

void TextToSpeechManager::setLanguage(const QLocale &locale) {
    m_tts->setLocale(locale);
}

QVector<QVoice> TextToSpeechManager::availableVoices() const {
    return m_tts->availableVoices();
}

QTextToSpeech::State TextToSpeechManager::state() const {
    return m_tts->state();
}
